package cn.com.yang.decorator.Interceptor;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Desc<cglib-2.2.2版本才有>
 * @Author 杨亿金
 * @Date 2020/8/30 18:17
 * @CopyRight
 * @Version
 */
public class TimeMethodInterceptor implements MethodInterceptor {
    private Object target;
    public TimeMethodInterceptor(Object target){
        this.target = target;
    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //记录当前系统时间
        //从1970.1.1
        long start =System.currentTimeMillis();
        Object value = method.invoke(target,objects);
        long end = System.currentTimeMillis();
        System.out.println("程序执行时长："+ (end - start));
        return value;
    }
}
